package com.qingluan.widget;



import javax.xml.transform.Templates;

import android.R.bool;
import android.R.integer;
import android.content.Context;
import android.provider.ContactsContract.CommonDataKinds.Event;
import android.util.Log;
import android.view.GestureDetector;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;

public class GestureListener  extends SimpleOnGestureListener implements OnTouchListener{
	//properties area
	private int velocity = 20;
	private int distance = 100; 
	
	//widget area
	private GestureDetector gestureDetector;  
	
	//context area 
	private Context context_this;
	
	
	public GestureListener(Context context) {
		// TODO Auto-generated constructor stub
		super();
		this.context_this = context;
		
		gestureDetector = new GestureDetector(context, this);  
	}
	
	//for action ,with pushing left or right 
	
	public boolean LeftMoveListener (int disX){
		return false;
		
	}
	public boolean RightMoveListener (int disX){
		return false;
		
	}
		
	public boolean FinallyMove( String tag) {
		// TODO Auto-generated method stub
		return false;
	}

	public boolean FirstMove(int dowX) {
		// TODO Auto-generated method stub
		return false;
	}

	public boolean RightMoveListener(MotionEvent e1, MotionEvent e2) {
		// TODO Auto-generated method stub
		return false;
	}

	public  boolean LeftMoveListener(MotionEvent e1, MotionEvent e2) {
		// TODO Auto-generated method stub
		return false;
	}

	
	/*
	 * for fling listen
	 */
	
	@Override
	public boolean onFling(MotionEvent e1 , MotionEvent e2 ,float velocityX ,float velocityY){
		String tag = "left";
		// e1：第1个ACTION_DOWN MotionEvent
		// e2：最后一个ACTION_MOVE MotionEvent
		try{
			if (e1.getX() - e2.getX() > 30 && Math.abs( velocityX) > velocity ){
				FinallyMove(tag);
			}
			if (e2.getX() - e1.getX() > 200 && Math.abs(velocityX) > velocity){
				tag = "right";
				FinallyMove(tag);
			}
		}catch (NullPointerException e){
			Log.d(tag, "error : \n "+e.toString());
		}
		return false;
		
	}
	

	@Override
	public boolean onTouch(View v, MotionEvent event) {
		int DowX = 0 ;
		// TODO Auto-generated method stub
		gestureDetector.onTouchEvent(event);
		/*
		switch (event.getAction()) {
		case MotionEvent.ACTION_DOWN:
			DowX  = (int) event.getX();
			//FirstMove(DowX);
			break;
		case MotionEvent.ACTION_UP:
			int tem =(int) event.getX();
			FinallyMove(DowX,tem);
			
			break;
		case MotionEvent.ACTION_MOVE:
			int tempX = (int) event.getX();
			if (DowX -tempX > 5){
				
				//int disLeft = DowX -tempX;
				//LeftMoveListener(disLeft);
			}
			if (tempX -  DowX >5){
				int disRight = tempX -DowX;
				//RightMoveListener(disRight);
			}
			break;
		default:
			break;
		}
		*/
		return false;
	}
	

	public int getDistance(){
		return distance;
	}
	
	public void setDistance(int distance){
		this.distance = distance;
	}
	
	public  int  getVelocity() {
		return this.velocity;
	}
	
	public  void setVelocity(int velocity) {
		this.velocity  = velocity ;
	}
	
	public GestureDetector getGestureDetector() {
		return gestureDetector;
	}
	
	public void setGestureDetector(GestureDetector gestureDetector) {  
		this.gestureDetector = gestureDetector;
	}

}
